package com.shan.thread;

/**
 * description
 * join是Thread类的一个方法，启动线程后直接调用，即join()的作用是：“等待该线程终止”，<br/>
 * 这里需要理解的就是该线程是指的主线程等待子线程的终止。也就是在子线程调用了join()方法<br/>
 * 后面的代码，只有等到子线程结束了才能执行，<br/>
 * @author shanzheng <br/>
 * @date 18:15 2019/1/11.<br/>
 * Modified By <br/>
 */
public class JoinThreadDemo {
    public static void main(String[] args) {
        JoinThread joinThread = new JoinThread();
        Thread thread = new Thread(joinThread, "线程");
        thread.start();
        for (int i = 0; i < 100; i++) {
            if (i > 10) {
                try {
                    thread.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("Main线程运行 --> " + i);
        }
    }
}


class JoinThread implements Runnable {

    @Override
    public void run() {
        for (int i = 0; i < 50; i++) {
            // 获取当前线程的名字
            System.out.println(i + "===>" + Thread.currentThread().getName());
        }
    }
}